home *** CD-ROM | disk | FTP | other *** search
/ C/C++ Users Group Library 1996 July / C-C++ Users Group Library July 1996.iso / vol_100 / 132_01 / dload < prev    next >
Text File  |  1985-08-19  |  7KB  |  274 lines

  1. ;+
  2. ;    Downline loader in assembly language for the Radio Shack
  3. ;    Color Computer
  4. ;-
  5. ;+
  6. ;    Ser6809 file must be appended for serial input function
  7. ;-
  8.     .=0x7A00
  9. ;+
  10. ;    dload    gets a line from the serial input port via serinp.
  11. ;    Loading begins with an 'S' and terminates with an 'X'.
  12. ;    Load format:    (Intel hex)
  13. ;        :<nn><00><aaaa><hh><hh>...<hh><ck>
  14. ;        where    <aaaa> is a four hex digit address
  15. ;            <00>   is two hex zeroes
  16. ;            <nn>    is a two digit hex count of the <hh> bytes
  17. ;            <hh>   is a two  hex digit byte
  18. ;            ':' is a starting colon
  19. ;-
  20. dload:
  21.     .byte    0x34,0x36    ;PSHS a,b,x,y
  22.     bsr    finds    ;look for the starting 'S'
  23. loop0:
  24.     bsr    getline
  25.     bcs    exit
  26.     bsr     echo    ;echo the line to the color screen
  27.     bsr    parse    ; decode the line and load memory
  28.     bcc    loop0
  29. exit:
  30.     .byte    0x35,0x36    ;PULS a,b,x,y
  31.     rts
  32. ;+
  33. ;    getline gets an input line from the serial port 
  34. ;    A line is defined as a non-zero character string 
  35. ;    bounded by characters less than 0x20. The string is
  36. ;    terminated by two nulls.
  37. ;    Inputs: none
  38. ;    Outputs: Characters to buffer buf.Carry clear if ok.
  39. ;         Carry set if ending 'X' detected.
  40. ;    Calls:     serinp
  41. ;-
  42. getline:
  43.     .byte    0x8E
  44.     .word    buf    ;LDX #buf
  45. getsyn:
  46.     jsr    serinp
  47.     cmp    a,$0x20    ;test for control char
  48.     blo    getsyn    ; if <20, keep looping
  49. getlup:
  50.     .byte    0xA7,0x80    ;sta ,x+
  51.     cmp    a,$0x58        ;test for 'X'
  52.     beq    getext
  53.     jsr    serinp
  54.     cmp    a,$0x20
  55.     bgt    getlup
  56. getext:
  57.     .byte    0x6F,0x80    ;clr 0,x+ tag string
  58.     .byte    0x6F,0x80    ;clr ,x+
  59.     cmp    a,$0x58        ;Termination due to 'X'?
  60.     bne    getexy
  61.     .byte    0x1A,01    ;ORCC #1, set carry
  62.     bra    getexx
  63. getexy:
  64.     .byte    0x1C,0xFE    ;clear the carry
  65. getexx:
  66.     rts
  67. ;+
  68. ;    finds searches for the starting 'S'
  69. ;-
  70. finds:
  71.     jsr    serinp
  72.     cmp    a,$0x53
  73.     bne    finds
  74.     rts
  75. ;+
  76. ;    parse    decodes the string and loads the memory locations
  77. ;    from the defined starting address.
  78. ;    Inputs: No parameters passed on input
  79. ;        Input line assumed stored in buffer buf
  80. ;    Output: Loads memory with bytes
  81. ;    Returns: carry set if error, clear if ok
  82. ;    Calls:    getadd,hexbin
  83. ;-
  84. parse:
  85.     .byte    0x8E
  86.     .word    buf    ;ldx #buf
  87.     .byte    0x30,01    ;LEAX 1,x  increment past starting colon
  88.     .byte    0xEC,0x81    ; LDD ,X++  get byte count
  89.     bsr    hexbin    ; get the byte count
  90.     bcs    parsex
  91.     tst    a
  92.     .byte    0x1a,01    ;set the carry bit to exit if need be
  93.     beq    parsex    ; end of file
  94.     mov    a,bytcnt
  95.     bsr    getadd    ; get starting address in Y
  96.     bcs    parsex    ; if failure on address
  97.     .byte    0x30,02 ;LEax 2,x  increment past null byte
  98. parlup:
  99.     .byte    0xEC,0x81    ;ldd ,x++ get two hex digits
  100.     bsr    hexbin        ;convert to binary
  101.     bcs    parsex1        ;if error in conversion,end of line
  102.     .byte    0xA7,0xA0    ;sta ,y+
  103.     dec    bytcnt
  104.     bne    parlup
  105. parsex1:
  106. ;+
  107. ;    This is where the diligent software engineer would check the
  108. ;    checksum.
  109. ;-
  110.     clr    a        ; clear carry bit for end of line exit
  111. parsex:
  112.     rts
  113. bytcnt:    .byte    0
  114. ;+
  115. ;    echo    outputs the received line to the color computer
  116. ;    screen.
  117. ;    Inputs:    none. Line assumed stored in buf
  118. ;    Outputs none.
  119. ;    All regs used except B,U
  120. ;    Calls:    none.
  121. ;-
  122. echo:
  123.     .byte    0x10,0x8E
  124.     .word    0x400    ;ldy #0x400
  125.     .byte    0x8E
  126.     .word    buf    ;Ldx #buf
  127. echlup:
  128.     .byte    0xA6,0x80    ;lda ,x+, get a character
  129.     .byte    0xA7,0xA0    ;sta ,y+, store the character
  130.     bne    echlup        ; if not the null tag yet
  131.     rts
  132. ;+
  133. ;    getadd    decodes an address from the head of the line in buf.
  134. ;    Inputs:X points to head of string to be decoded
  135. ;    Returns: Carry set if bad address
  136. ;         carry cleared and address in Y if ok
  137. ;         X is advanced by four bytes
  138. ;    Calls:    hexbin
  139. ;    Regs: a,b,x,y
  140. ;-
  141. getadd:
  142.     .byte    0xEC,0x81    ;ldd ,x++ get two hex digits
  143.     bsr    hexbin
  144.     bcs    getadx        ; if conversion error
  145.     .byte    0x34,02        ; PSHS A save top byte
  146.     .byte    0xEC,0x81    ;ldd ,x++ get two hex digits
  147.     bsr    hexbin
  148.     .byte    0x1E,0x89    ;exg a,b, move converted low byte to b
  149.     .byte    0x35,02        ; PULS a
  150.     .byte    0x1E,0x02    ;exg D,Y, move address to Y
  151. getadx:
  152.     rts            ; exit, carry possibly set
  153. ;+
  154. ;    hexbin    converts two hex digits in a and b to a
  155. ;    single byte left in a
  156. ;    Inputs:    two ascii encoded hex digits in a and b
  157. ;    Returns: carry clear - byte in a
  158. ;         carry set  - conversion error
  159. ;    Calls:    hex1bin
  160. ;    Regs:    a,b,
  161. ;-
  162. hexbin:
  163.     bsr    hex1bin
  164.     bcs    hexx    ; if error
  165.     .byte    0x1E,0x89
  166.     ; exg a and b
  167.     asl    b
  168.     asl    b
  169.     asl    b        ; move up nybble to top of byte
  170.     asl    b
  171.     bsr    hex1bin    ; convert second ascii in a to hex in a
  172.     bcs    hexx
  173.     .byte    0x34,4    ; PSHS b
  174.     .byte    0xAA,0xE0    ;ORAA ,S+ or in high byte
  175. hexx:
  176.     rts
  177. ;+
  178. ;hex1bin    is the actual ascii to binary (hex) converter.
  179. ;    INPUT:    ascii coded hex digit in a
  180. ;    Output:    carry clear, hex value in a
  181. ;        carry set,   converstion error , not hex
  182. ;    Calls:    none
  183. ;    Regs:    a only used
  184. ;-
  185. hex1bin:
  186.     .byte    0x80,0x30    ;sub a , #'0
  187.     bcs    hex1x    ; a< '0'
  188.     cmp    a,$0xa
  189.     bcs    hexok    ; 0 < a < 9
  190.     .byte    0x80,7        ;sub a ,#7
  191.     cmp    a,$0xA        ; test for result < 0xa
  192.     bcs    hex1x        ; a < 0xa if carry set
  193.     cmp    a,$0x10
  194.     bcc    hex1x    ; a>= 0x10
  195. hexok:
  196.     .byte    0x1c,0xFE ;andcc 0xfe, clear carry bit
  197.     bra    hex2x
  198. hex1x:
  199.     .byte    0x1A,0x01 ; orcc #1, set carry bit
  200. hex2x:
  201.     rts
  202. ;+
  203. ;    line buffer storage
  204. ;-
  205. buf:
  206.     .blkb    64
  207.     .blkb    64
  208. ;+
  209. ;    Serial Input routine for the 6809
  210. ;    I/O port configured for Radio Shack color computer
  211. ;-
  212. bitime    =    20    ;Time constant for 4800 baud bit interval
  213. halfbit    =    5    ; 1/2 bit time for center bit sync
  214. IPORT    =    0xFF22    ; Color computer i/o port address
  215. IMASK    =    1    ; Bit position of input bit in port
  216. ;
  217. ;+
  218. ;    input call to receive a character
  219. ;-
  220. serinp:
  221.     .byte    0x1A,0x50    ;orcc 50, kill interrupts
  222.     bsr    inwait        ;get character
  223.     rts            ;exit, character in a
  224. ;
  225. ;+
  226. ;    inwait    waits for an input character to start and
  227. ;    receives it.
  228. ;-
  229. inwait:
  230.     mov    IPORT,a
  231.     and    $IMASK,a        ; Get the bit out
  232.     beq    inwait        ; wait on line = 0 
  233. ;
  234. serget:
  235.     .byte    0x34,0x34    ;PSHS X,Y,B
  236.     .byte    0x10,0x8E,0,8    ;LDY #8 = bitcounter
  237.     .byte    0x8E
  238.     .word    halfbit    ;LDX bitime /2 
  239.     clr    a        ; clear receive register
  240. ;+
  241. ;    sync up on the start bit transition
  242. ;-
  243. sync:
  244.     mov    IPORT,b    ;get port value
  245.     and    $IMASK,b        ;Test bit value
  246.     bne    sync        ;wait on start bit = 1
  247. start:
  248.     .byte    0x30,0x1F    ;LEAX -1,X
  249.     beq    assemble    ;one half bit time has expired
  250.     mov    IPORT,b
  251.     and    $IMASK,b
  252.     beq    start        ;count down the start bit
  253.     mov    $-1,a        ; Glitch on start,return error
  254.     .byte    0x35,0x34    ;PULS X,Y,B
  255.     rts            ;error exit
  256. assemble:
  257.     .byte    0x8E
  258.     .word    bitime        ; set one bit time wait
  259. assemb1:
  260.     .byte    0x30,0x1F    ; LEAX -1,x ,dec bit timer
  261.     bne    assemb1
  262.     mov    IPORT,b
  263.     and    $IMASK,b
  264.     beq    assemb2
  265.     or    $0x80,a        ; or in the bit
  266. assemb2:
  267.     .byte    0x31,0x3F    ;LEAY -1,Y decr. bit count
  268.     beq    seriox        ; exit if done
  269.     lsr    a        ; move the bit down for the next pass
  270.     bra    assemble
  271. seriox:
  272.     .byte    0x35,0x34    ;PULS X,Y,B
  273.     rts            ; character in A
  274. Eç/BLOç%BLSç#BLTç-BMIç+BNEç&BPLç*BRAç BRNç!BSRçìBVCç(BVSç)CLRAüOCLRBü_CLRîCMPAïüCMPBï┴CMPDìâCMPSÄîCMPUÄ